package com.zkjl.protect_business.common;

import com.zkjl.protect_business.entity.User;

public class UserThreadLocal {

    //把构造函数私有，外面不能new，只能通过下面两个方法操作
    private UserThreadLocal(){

    }

    private static final ThreadLocal<User> LOCAL = new ThreadLocal<User>();

    public static void set(User user){
        LOCAL.set(user);;
    }

    public static User get(){
        return LOCAL.get();
    }

    public static String getUserId() {
        User user = get();
        if (user != null) {

            String id = user.getId();
            return id;
        }
        return "";
    }

    public static String getUserName() {
        User user = get();
        if (user != null) {
            String name = user.getRealName();
            return name;
        }
        return "";
    }


    public static String getUserRole() {
        User user = get();
        if (user != null) {
            String name = user.getSysRoleName();
            return name;
        }
        return "";
    }


    public static String getOrg() {
        User user = get();
        if (user != null) {
            String org = user.getOrg();
            return org;
        }
        return "";

    }

    public static String getOrgId() {
        User user = get();
        if (user != null) {
            String orgId = user.getOrgId();
            return orgId;
        }
        return "";
    }

    public static void remove() {
        LOCAL.remove();
    }

}
